package cn.syc.struck.demo.bean.parcelable;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by chenzz on 2017/4/12.
 * 用法
 * <p>
 * <p>
 * //传递对象
 * Info bean = new Info();
 * bean.name = "chenzz";
 * bean.email = "tim@qq.com";
 * bean.money = 10000.0d;
 * bean.time = System.currentTimeMillis();
 * bean.type = 1;
 * <p>
 * Bundle bundle = new Bundle();
 * bundle.putParcelable("bean", bean);
 * Intent intent = new Intent(BasicActivity.this,
 * LoginActivity.class);
 * intent.putExtras(bundle);
 * startActivity(intent);
 * <p>
 * //获取对象
 * Info b = getIntent().getExtras().getParcelable("bean");
 */

public class Info implements Parcelable {
    //long a = 100000L,b=0L;
    //’\u0000’,char c1 = 'a';char c2 = '上';
    public String name;
    public String email;
    public int type;
    public double money;
    public long time;
    public boolean isAdministrator;
    public char tag;

    public Info() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeString(this.email);
        dest.writeInt(this.type);
        dest.writeDouble(this.money);
        dest.writeLong(this.time);
        dest.writeByte(this.isAdministrator ? (byte) 1 : (byte) 0);
        dest.writeInt(this.tag);
    }

    protected Info(Parcel in) {
        this.name = in.readString();
        this.email = in.readString();
        this.type = in.readInt();
        this.money = in.readDouble();
        this.time = in.readLong();
        this.isAdministrator = in.readByte() != 0;
        this.tag = (char) in.readInt();
    }

    public static final Creator<Info> CREATOR = new Creator<Info>() {
        @Override
        public Info createFromParcel(Parcel source) {
            return new Info(source);
        }

        @Override
        public Info[] newArray(int size) {
            return new Info[size];
        }
    };
}
